﻿Imports System.Data.SqlClient
Public Class equipement
    Public idEquip As Integer
    Public categorie As String
    Public types As List(Of typeEquipement)
    Public Sub New()
        Me.types = New List(Of typeEquipement)
    End Sub
    Public Sub mesTypes()
        Cmd = New SqlCommand("SELECT * FROM [Salle_Mariage].[dbo].[trTypeEquipement] where [idEquipement] = " & Me.idEquip, Con)
        Dr = Cmd.ExecuteReader
        If Dr.HasRows Then
            types = New List(Of typeEquipement)
        End If
        While Dr.Read
            types.Add(New typeEquipement With {.idType = Dr.GetInt32(0), .idEquip = Dr.GetInt32(1), .libelle = Dr.GetString(2), .prixLoc = Dr.GetDouble(3), _
                                               .quantStock = Dr.GetInt16(4), .Photo = Dr(6), .remarque = Dr.GetString(5)})
        End While
        Dr.Close()
    End Sub
    Public Sub ajouterType(ByVal typEquip As typeEquipement)
        Cmd = New SqlCommand("INSERT INTO [Salle_Mariage].[dbo].[trTypeEquipement] " &
           "([idEquipement] " &
           ",[libelle] " &
           ",[prixLocation] " &
           ",[quantiteStock] " &
           ",[remarque] " &
           ",[photo]) " &
     "VALUES (" & Me.idEquip & ",@libelle,@prixLocation," & typEquip.quantStock & ",@remarque,@photo)", Con)
        Cmd.Parameters.Add("@Photo", SqlDbType.VarBinary).Value = typEquip.Photo
        Cmd.Parameters.Add("@libelle", SqlDbType.VarChar).Value = typEquip.libelle
        Cmd.Parameters.Add("@remarque", SqlDbType.VarChar).Value = typEquip.remarque
        Cmd.Parameters.Add("@prixLocation", SqlDbType.Float).Value = typEquip.prixLoc
        Cmd.ExecuteNonQuery()
        Cmd.Parameters.Clear()
        Cmd.CommandText = "select @@identity"
        typEquip.idType = Cmd.ExecuteScalar
        Me.types.Add(typEquip)
    End Sub
    Public Sub supprimerType(ByVal idType As Integer)
        Cmd = New SqlCommand("DELETE FROM [Salle_Mariage].[dbo].[trTypeEquipement] WHERE idType = " & idType, Con)
        Cmd.ExecuteNonQuery()
        Me.types.Remove((From t In Me.types Where t.idType = idType)(0))
    End Sub
    Public Sub modifierTypeEquipement(ByVal typEquip As typeEquipement)
        Cmd = New SqlCommand("UPDATE [Salle_Mariage].[dbo].[trTypeEquipement] " &
            "SET [libelle] = @libelle,[prixLocation] = " & typEquip.prixLoc & ",[quantiteStock] = " & typEquip.quantStock & ",[photo] = @photo WHERE idType = " & typEquip.idType, Con)
        Cmd.Parameters.Add("@libelle", SqlDbType.VarChar).Value = typEquip.libelle
        Cmd.Parameters.Add("@photo", SqlDbType.VarBinary).Value = typEquip.Photo
        Cmd.ExecuteNonQuery()
    End Sub

End Class
